//
//  QSVisitScreeningView.m
//  DigitalEconomy_iOS
//
//  Created by Ding on 2020/3/29.
//  Copyright © 2020 DingC. All rights reserved.
//

#import "QSVisitScreeningView.h"

@implementation QSVisitScreeningView
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor QSColorWhiteFFFFFF];
        self.layer.cornerRadius = 5;
        self.layer.masksToBounds = YES;
        [self configSubView];
    }
    return self;
}

- (void)configSubView{
    [self addSubview:self.timeScreenButton];
    
    [self addSubview:self.enterpriseScreenButton];
     
    [self addSubview:self.searchButton];
    
    [self.timeScreenButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.height.equalTo(self);
        make.width.offset(kRealValue((kScreenWidth - 20) / 3));
    }];
    [self.enterpriseScreenButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.equalTo(self.timeScreenButton);
        make.left.equalTo(self.timeScreenButton.mas_right).offset(0);
    }];
    
    [self.searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.equalTo(self.timeScreenButton);
        make.right.equalTo(self.mas_right).offset(0);
    }];
    
}

#pragma mark - Lazy loading
- (UIButton *)timeScreenButton{
    if (!_timeScreenButton) {
        _timeScreenButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_timeScreenButton setTitle:@"时间筛选" forState:UIControlStateNormal];
        [_timeScreenButton setButtonRightImageWithButton:_timeScreenButton];
        [_timeScreenButton setImage:[UIImage imageNamed:@"ic_selectpeople"] forState:UIControlStateNormal];

        _timeScreenButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        [_timeScreenButton setTitleColor:[UIColor QSColorBlack434343] forState:UIControlStateNormal];
        _timeScreenButton.titleLabel.font = [UIFont QSFontOfSize14];
        [_timeScreenButton addTarget:self action:@selector(timeScreeningAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _timeScreenButton;
}

- (UIButton *)enterpriseScreenButton{
    if (!_enterpriseScreenButton) {
        _enterpriseScreenButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_enterpriseScreenButton setTitle:@"企业筛选" forState:UIControlStateNormal];
        [_enterpriseScreenButton setButtonRightImageWithButton:_enterpriseScreenButton];
        [_enterpriseScreenButton setImage:[UIImage imageNamed:@"ic_selectpeople"] forState:UIControlStateNormal];
        _enterpriseScreenButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        [_enterpriseScreenButton setTitleColor:[UIColor QSColorBlack434343] forState:UIControlStateNormal];
        _enterpriseScreenButton.titleLabel.font = [UIFont QSFontOfSize14];
        [_enterpriseScreenButton addTarget:self action:@selector(enterpriseScreenAction:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _enterpriseScreenButton;
}

- (UIButton *)searchButton{
    if (!_searchButton) {
       _searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
       [_searchButton setTitle:@"清除筛选" forState:UIControlStateNormal];
       [_searchButton setTitleColor:[UIColor colorWithHexString:@"#128BEC"] forState:UIControlStateNormal];
       _searchButton.titleLabel.font = [UIFont QSFontOfSize14];
        _searchButton.titleLabel.textAlignment = NSTextAlignmentRight;
        [_searchButton addTarget:self action:@selector(searchAction:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _searchButton;
}

- (void)timeScreeningAction:(UIButton *)sender{
    NSLog(@"点击了时间筛选");
    if (self.delegate && [self.delegate respondsToSelector:@selector(visitScreeningView:didSelectTimeScreenButton:)]) {
        [self.delegate visitScreeningView:self didSelectTimeScreenButton:sender];
    }
}

- (void)enterpriseScreenAction:(UIButton *)sender{
    if (self.delegate && [self.delegate respondsToSelector:@selector(visitScreeningView:didSelectEnterpriseScreenButton:)]) {
           [self.delegate visitScreeningView:self didSelectEnterpriseScreenButton:sender];
       }
}

- (void)searchAction:(UIButton *)sender{
    if (self.delegate && [self.delegate respondsToSelector:@selector(visitScreeningView:didSelectSearchButton:)]) {
           [self.delegate visitScreeningView:self didSelectSearchButton:sender];
       }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
